<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAutoload() {
        $front = $this->bootstrap("frontController")->frontController;
        $front->addModuleDirectory(APPLICATION_PATH . '/modules/');        
    }
        
    protected function _initPlugins() {
        $front = Zend_Controller_Front::getInstance();
        $front->registerPlugin(new Application_Plugin_Acl());
    }

    protected function _initResourceLoader() {
        $loader = new Zend_Loader_Autoloader_Resource(
            array(
                'basePath' => APPLICATION_PATH,        
                'namespace' => ''
            )
        );
        
        $loader->addResourceType('block', 'blocks', 'Block');
    }

    protected function _initHelpers() {
        require_once 'Project/Controller/Action/Helper/Block.php';
        Zend_Controller_Action_HelperBroker::addHelper(
            new Project_Controller_Action_Helper_Block()
        );
    }

    public function _initRoute() {      
        $router = Zend_Controller_Front::getInstance()->getRouter();        
        $routeStatic = new Zend_Controller_Router_Route(
                '/static/:name',
                array(
                    'controller' => 'static',
                    'action'     => 'index'
                ), 
                array(
                    'name' => '[\w\-]+'
                )
        );
        $router->addRoute('static', $routeStatic);

        $routePost = new Zend_Controller_Router_Route(
                '/post/:name',
                array(
                    'controller' => 'feed',
                    'action'     => 'post'
                ), 
                array(
                    'name' => '[\w\-]+'
                )
        );
        $router->addRoute('post', $routePost); 

        $routeDepartments = new Zend_Controller_Router_Route(
                '/department/:dept_name',
                array(
                    'controller' => 'department',                    
                    'action'     => 'index'                    
                ), 
                array(
                    'dept_name' => '[\w\-]+',
                    'name'      => '[\w\-]+'
                )
        );
        $router->addRoute('department', $routeDepartments);       

        $routeDepartments = new Zend_Controller_Router_Route(
                '/department/:dept_name/:action/:category/*',
                array(
                    'controller' => 'department',                    
                    'action'     => 'index'                    
                ), 
                array(
                    'dept_name' => '[\w\-]+',
                    'category'  => '[\w\-]+',
                    'action'    => '[\w\-]+'
                )
        );
        $router->addRoute('department_content', $routeDepartments);

        $routeDepartments = new Zend_Controller_Router_Route(
                '/department/post/:name/*',
                array(
                    'controller' => 'department',                    
                    'action'     => 'post'                    
                ), 
                array(
                    'name' => '[\w\-]+'
                )
        );
        $router->addRoute('department_post', $routeDepartments);


        $departmentFeed = new Zend_Controller_Router_Route(
                '/department/:dept_name/feed/:category/*',
                array(
                    'controller' => 'department',                    
                    'action'     => 'feed'                    
                ), 
                array(
                    'category'  => '[\w\-]+',
                    'dept_name' => '[\w\-]+'
                )
        );
        //$router->addRoute('department_feed', $departmentFeed);

        $byTag = new Zend_Controller_Router_Route(
                '/posts-by-tag/tag_id/:tag_id',
                array(
                    'controller' => 'feed',                    
                    'action' => 'posts-by-tag'                    
                ), 
                array(
                    'tag_id' => '[0-9]+'
                )
        );
        $router->addRoute('by_tag', $byTag);        

        $feed = new Zend_Controller_Router_Route(
                '/feed/:category_alias/*',
                array(
                    'controller' => 'feed',                    
                    'action' => 'news'                    
                ), 
                array(
                    'category_alias' => '[\w\-]+'
                )
        );
        $router->addRoute('feed', $feed);  

        $custom = new Zend_Controller_Router_Route(
                '/custom/:alias/*',
                array(
                    'controller' => 'custom',                    
                    'action'     => 'index'                    
                ), 
                array(
                    'alias' => '[\w\-]+'
                )
        );
        $router->addRoute('custom', $custom);        
    }
}

